package com.example.teaching_server.service;

import com.example.teaching_server.entity.ExtracurricularRecording;
import com.example.teaching_server.repository.ExtracurricularRecordingRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 课外活动录制服务
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ExtracurricularRecordingService {

    private final ExtracurricularRecordingRepository recordingRepository;

    /**
     * 根据条件查询录制记录
     */
    public List<ExtracurricularRecording> getRecordingsByCriteria(Integer termId, Integer classId) {
        log.debug("查询课外活动录制记录: termId={}, classId={}", termId, classId);

        if (termId != null && classId != null) {
            return recordingRepository.findByTermIdAndClassId(termId, classId);
        } else if (termId != null) {
            return recordingRepository.findByTermId(termId);
        } else if (classId != null) {
            return recordingRepository.findByClassId(classId);
        } else {
            log.warn("未指定查询条件，返回空列表");
            return List.of();
        }
    }
}
